package com.david.rabbitmq.topic;

import com.david.rabbitqm.util.ChannelUtlis;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

import java.io.IOException;

/**
 * @author David
 * @version V1.0
 * @Package com.david.rabbitmq.topic
 * @date 2021/7/17 10:39
 */
public class TopicAnimalColorConsumer {
    private static final String EXCHANGE_NAME = "topic_animal";

    public static void main(String[] args) throws IOException {
        Channel channel = ChannelUtlis.getChannel();
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC);
        String queueName = channel.queueDeclare().getQueue();
        channel.queueBind(queueName, EXCHANGE_NAME, "*.orange.*");
        DeliverCallback callback = (consumerTag, message) -> System.out.println("*.orange.* 匹配到的消息："
                + new String(message.getBody(), "UTF-8"));
        channel.basicConsume(queueName, true, callback, consumerTag -> {});
    }
}
